1. /* slfctout.cpp by K.Tsuru */
  2. // function ID = 222 DRADIX, BRADIX
  3. /******************************************************************************
  4. SLong and SInteger classes
  5. It cuts out a "size" part from "src[pos]" and puts into dest[0]...dest[size-1].
  6. The sign is the same as that of "src".
  7. src[pos]....src[pos+size-1]
  8. If pos+size-1 < src.aTail it sets zero.
  9. *******************************************************************************/
  10. #ifndef SN_H
  11. #include "sn.h"
  12. #endif
  13. void SLong::SLCutOut(SLong& dest, const SLong& src, uint pos, uint size){
  14. dest.SetType(src.Type());
  15. if( (src.Sign(222) == 0) || (pos > src.Head() ) || (pos+size < src.Tail()+1u) ){
  16. dest.SetZero(); return;
  17. }
  18. uint n_copy = min(size, src.figure.size() - pos);
  19. dest.valloc(n_copy, -1);
  20. fType* df = dest.figure.Elements();
  21. memcpy(df, src.ReadFigures()+pos, n_copy*sizeof(fType) );
  22. dest.figure.clear(n_copy);
  23. /*
  24. It gets the figure positions. It must be noticed that there are many zeros
  25. in the middle region such as
  26. p+s-1 p
  27. src = 0000 0000 5000 0000 0000 0000 .... 0000 0000 1234 5678 ....
  28. */
  29. int j = 0;
  30. while( (df[j] == 0) && (j < (int)n_copy)) j++;
  31. if(j == (int)n_copy){
  32. dest.SetSign(0); return;
  33. }
  34. dest.aTail = (uint)j;
  35. #ifndef NDEBUG
  36. assert( (uint)j < n_copy);
  37. #endif
  38. j = (int)n_copy-1;
  39. while(df[j] == 0) j--;
  40. dest.aHead = (uint)j;
  41. #ifndef NDEBUG
  42. assert(j >= 0);
  43. #endif
  44. dest.SetSign(src.Sign()); // dest != 0
  45. }

slfctout.cpp : last modifiled at 2017/03/13 14:32:00(1,474 bytes)
created at 2017/10/07 10:26:50
The creation time of this html file is 2017/11/09 14:52:03 (Thu Nov 09 14:52:03 2017).